/**
 *    Copyright 2009-2019 the original author or authors.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */
package org.apache.ibatis.type;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * 类型转换处理器
 *
 * @author Clinton Begin
 */
public interface TypeHandler<T> {

    /**
     *  根据参数索引和jdbc类型设置PreparedStatement语句中的值,即将? 替换为实际值。
     *
     * @param ps        PreparedStatement 语句
     * @param i         参数索引
     * @param parameter 参数
     * @param jdbcType  jdbc类型
     * @throws SQLException SQL异常
     */
    void setParameter(PreparedStatement ps, int i, T parameter, JdbcType jdbcType) throws SQLException;

    /**
     * 获取指定ResultSet中指定名称的列对应的值，并转换为相应的JAVA类型
     *
     * @param rs         ResultSet
     * @param columnName 列名称
     * @return 值
     * @throws SQLException SQL异常
     */
    T getResult(ResultSet rs, String columnName) throws SQLException;

    /**
     * 获取指定ResultSet中指定索引下面的列对应的值，并转换为相应的JAVA类型
     *
     * @param rs          ResultSet
     * @param columnIndex 列索引
     * @return 值
     * @throws SQLException SQL异常
     */
    T getResult(ResultSet rs, int columnIndex) throws SQLException;

    /**
     * 获取指定存储过程(CallableStatement)中指定索引下标对应的值，并转换为相应的JAVA类型
     *
     * @param cs          存储过程
     * @param columnIndex 列索引
     * @return 值
     * @throws SQLException SQL异常
     */
    T getResult(CallableStatement cs, int columnIndex) throws SQLException;

}
